/**
 * Created by BaiYJ on 2017/4/21.
 */
var STATUS=[
    SUCCESS=0,
    ERROR =1

]

var editor; // use a global for the submit and return data rendering
var repeat;
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
$('#addButton').on('click', function () {

    var ids=[];
    var otTime=[];
    var otLength=[];
    var otReason=[];
    var otType=[];
    $("input[name='id']").each(function(index,item) {

        ids[index]=$(this).val();
    });
    // $("input[name='otTime']").each(function(index,item) {
    //
    //     otTime[index]=$(this).val();
    // });
    $("input[name='otLength']").each(function(index,item) {//普通加班时长

        otLength[index]=$(this).val();
    });
    // $("input[name='otReason']").each(function(index,item) {
    //
    //     otReason[index]=$(this).val();
    // });
    $("input[name='otType']").each(function(index,item) {//假期加班时长

        otType[index]=$(this).val();
    });
 

    $.ajax({
        type: "POST",
        url: "/commis/api/overtime/create",
        dataType: "json",
        data: {
            ids:ids,
            otLength:otLength,
            otType:otType,

        },
        cache: false,

        success: function(result){
            var status =result.status;
            var data = result.data;
            if(status==0) {
                alert("添加成功,请记得上传对应详细文件");
                $.ajax({
                    url: '/commis/api/index/notify',
                    type: "GET",
                    async: false,
                    dataType: 'json',
                    success: function (result) {
                        if (result.status == 0) {
                            countNotify(result);
                        }else{
                            alert(result.msg);
                        }


                    }, error: function (msg) {
                        alert("发生错误");
                    }
                })
            }else if(status==1){
                alert("添加失败，请检查");
            }else if(status==4){
                alert("已经存在当月数据,请不要重复提交！，若想要覆盖数据，请联系社区管理员");
            }else if(status==3){
                alert("请重新登录");
                document.location.href = "../../login.html";
            }

        }, error: function () {
            alert("发生错误,请检查所填写项是否都为整型数字，如果没有请填写0");

        }
    });




});
$(document).ready(function () {
    var oDate = new Date(); //实例一个时间对象；
    var year =oDate.getFullYear();   //获取系统的年；
    var month =oDate.getMonth()+1;   //获取系统月份，由于月份是从0开始计算，所以要加1
    repeat =getUrlParam("repeat");
    if(repeat!=1){
        repeat =0;
    }
    $("#inputfile").fileinput({
        uploadUrl: "/commis/api/upload/uploadOvertimeFile?repeat="+repeat, // server upload action
        uploadAsync: true,
        showPreview: false,
        language: 'zh',
        maxFileCount: 1,
        elErrorContainer: ".file-error",
        allowedFileExtensions: ["xls", "xlsx"]
    }).on("fileuploaded", function (event, data, id, index) {
        var response = data.response;
        var status = response.status;
        var out;
        if (status == 0) {
            var fname = data.files[index].name;
            out = '上传文件  - ' +
                fname + ' 成功.';
            alert("上传成功");
        }

        else if (status == 1) {
            alert("上传失败");
        } else {
            out = '当月文件已经上传，请不要重复上传';
            alert("当月文件已经上传，请不要重复上传");

        }
        $('.file-success').html(out);
        $('.file-success').fadeIn('slow');
        // $('#inputfile').parent().prev().hide();


    }).on('fileclear', function (event) {
        $('#inputfile').val("");
        // $('#inputfile').parent().prev().show();
        $('.file-success').hide();

    });
    $.ajax({
        url: '/commis/api/person/communityPerson',
        async: false,
        dataType: 'json',
        success: function (response) {
            var data =response.data;
            // var date=getNowFormatDate();
            for (var i = 0; i < data.length; i++) {
                $("#mytbody").append("<tr><td>"+data[i].personName+"<input name='id' value='"+data[i].personId+"' type='hidden'/></td>"
                +"<td><input name='otLength' value='' stylei='width: 40px'/></td>"
                    +"<td><input name='otType' value='' stylei='width: 40px'/></td>"
                +"<td>"+year+"</td>"
                +"<td>"+month+"</td>"
                +"</tr>");
            }


        }, error: function () {
                alert("发生错误");

        }
    });





})
//设置框架
$(function () {
    $("#page_style").frame({
        float: 'left',
        menu_nav: '.Quick_operation',
        color_btn: '.skin_select',
        Sellerber_menu: '.list_content',
        Sellerber_header: '.Sellerber_header',
    });
});
$("#iframe_box").niceScroll({
    cursorcolor: "#888888",
    cursoropacitymax: 1,
    touchbehavior: false,
    cursorwidth: "5px",
    cursorborder: "0",
    cursorborderradius: "5px"
});
/*********************/
require.config({
    paths: {
        echarts: './js/dist'
    }
});